import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { defHttp } from '/@/utils/http/axios';

export const columns: BasicColumn[] = [
  {
    title: '字段名称',
    dataIndex: 'fieldName',
  },
  {
    title: '字段编码',
    dataIndex: 'fieldCode',
  },
  {
    title: '字段类型',
    dataIndex: 'fieldType',
  },
  {
    title: '字典编码（选择类型字段适用）',
    dataIndex: 'dictCode',
  },
  {
    title: '字段描述',
    dataIndex: 'fieldDesc',
  },
  {
    title: '产品分类编码',
    dataIndex: 'goodsCategory',
  },
  {
    title: '更新日期',
    dataIndex: 'updateTime',
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    label: '产品分类',
    field: 'goodsCategory',
    component: 'JTreeDict',
    componentProps: {
      async: true,
      parentCode: 'C06',
      field: 'code',
      placeholder: '请选择产品分类',
      allowClear: true,
      showSearch: true,
    },
    colProps: { span: 8 },
  },
];

export const formSchema: FormSchema[] = [
  // TODO 主键隐藏字段，目前写死为ID
  { label: '', field: 'id', component: 'Input', show: false },
  {
    label: '产品分类',
    field: 'goodsCategory',
    component: 'JTreeDict',
    componentProps: {
      async: true,
      parentCode: 'C06',
      field: 'code',
      placeholder: '请选择产品分类',
      allowClear: true,
      showSearch: true,
    },
    required: true,
  },
  // {
  //   label: '产品分类',
  //   field: 'goodsCategory',
  //   component: 'Cascader',
  //   componentProps: {
  //     api: () => defHttp.get({ url: '/sys/category/rootList' }).then((res) => res.records || res),
  //     childrenField: 'children',
  //     labelField: 'title',
  //     valueField: 'code',
  //     placeholder: '请选择产品分类',
  //     // showSearch: true,
  //     allowClear: true,
  //     expandTrigger: 'hover',
  //     changeOnSelect: true,
  //     resultField: 'records',
  //   },
  //   required: true,
  // },
  {
    label: '字段名称',
    field: 'fieldName',
    component: 'Input',
    componentProps: {
      placeholder: '请输入字段名称',
    },
    required: true,
  },
  {
    label: '字段编码',
    field: 'fieldCode',
    component: 'Input',
    componentProps: {
      placeholder: '请输入字段编码',
    },
    required: true,
  },
  {
    label: '字段类型',
    field: 'fieldType',
    component: 'Select',
    componentProps: {
      placeholder: '请选择字段类型',
      options: [
        { label: '文本输入', value: 'Input' },
        { label: '下拉选择', value: 'JDictSelectTag' },
      ],
    },
    required: true,
  },
  {
    label: '字典编码',
    field: 'dictCode',
    component: 'ApiSelect',
    componentProps: {
      api: () => defHttp.get({ url: '/sys/dict/list' }),
      showSearch: true,
      numberToString: true,
      placeholder: '请选择字典编码',
      labelField: 'dictName',
      valueField: 'dictCode',
      resultField: 'records',
    },
    ifShow: ({ values }) => values.fieldType === 'JDictSelectTag',
  },
  {
    label: '字段描述',
    field: 'fieldDesc',
    component: 'InputTextArea',
    componentProps: {
      placeholder: '系统自动生成',
    },
  },
];
